package com.langshixiaobai.domain.service.discount.impl;

import com.langshixiaobai.domain.model.valobj.DiscountTypeEnum;
import com.langshixiaobai.domain.model.valobj.GroupBuyActivityDiscountVO;
import com.langshixiaobai.domain.service.discount.IDiscountCalculateService;

import java.math.BigDecimal;

// 抽象模板
public abstract class AbstractDiscountCalculateService  implements IDiscountCalculateService {


    @Override
    public BigDecimal calculate(String userId, BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
        //如果此次商品限定人群优惠
        if(DiscountTypeEnum.TAG.equals(groupBuyDiscount.getDiscountType())){

            if(!filterTagId(userId, groupBuyDiscount.getTagId())){
                //不是特定人群优惠
                return originalPrice;
            }

        }
        return doCalculate(originalPrice,groupBuyDiscount );
    }



    // 人群过滤 - 限定人群优惠
    private boolean filterTagId(String userId, String tagId) {
        // todo xiaofuge 后续开发这部分
        return true;
    }

    protected abstract BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount);
}
